package com.example.werthwedemo0309.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.werthwedemo0309.MainActivity;
import com.example.werthwedemo0309.R;

import java.util.ArrayList;
import java.util.List;

public class WeatherFragment extends Fragment {
    private View root;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        root= inflater.inflate(R.layout.fragment_weather, container, false);
        initView();
        return root;
    }

    private void initView() {
        RecyclerView recyclerView=root.findViewById(R.id.recle);
        LinearLayoutManager llm = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(llm);
        List<ContactModel> data=new ArrayList<>();
        for (int i = 0; i < MainActivity.response.body().getResult().getFuture().size(); i++) {
            ContactModel item=new ContactModel();
            item.setListDay(MainActivity.response.body().getResult().getFuture().get(i).getDate());
            item.setListInfo(MainActivity.response.body().getResult().getFuture().get(i).getWeather());
            item.setListfaut(MainActivity.response.body().getResult().getFuture().get(i).getTemperature());
            data.add(item);
        }
        ContactAdapter adapter=new ContactAdapter(getContext());
        adapter.setData(data);
        recyclerView.setAdapter(adapter);
    }

}